<template>
    <div>
        <h1>注册界面</h1>
        <table class="table" border="1">
            
        <tr>
            <td>用户名</td>
            <td><input type="text" placeholder="请输入用户名" v-model="U_Lname"></td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" placeholder="请输入密码" v-model="U_Lpass">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="handleAdd">注册</button>
            </td>
        </tr>

        </table>

    </div>
</template>
<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const U_Lname = ref('');
const U_Lpass = ref('');

const router = useRouter();

const handleAdd = () => {

    if(U_Lname.value=='' || U_Lpass.value=='')
    {
        alert('用户名或密码不能为空');
        return;
    }

    axios({
        method: 'post',
        url: 'http://localhost:59812/api/End/UserAdd',
        data: {
            U_Lname: U_Lname.value,
            U_Lpass: U_Lpass.value
        }
    })
    // 请求成功
        .then(res => {
            if(res.data>0)
            {
                alert('注册成功');
                router.push('/UserLogin');
            }
            else
            {
                alert('注册失败');
            }
            
        })
        // 请求失败
        .catch(err => {
            console.log(err);
        })
}


</script>
